#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
long long T,mod,n,ans=0,dp[200005][455]; 
int main()
{
	freopen("moon.in","r",stdin);
	freopen("moon.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for(long long i=0;i<=450;i++)
	{
		dp[0][i]=1;
	}
	cin>>T>>mod;
	for(long long i=1;i<=200000;i++)
	{
		for(long long j=1;j<=450;j++)
		{
			dp[i][j]=((i>=j?dp[i-j][j]:0)+dp[i][j-1])%mod;
		}
	}
	while(T--)
	{
		ans=0;
		cin>>n;
		for(long long i=1;i*i<=n;i++)
		{
			if((n-i*i)%2==0)
			{
				ans=(ans+dp[(n-i*i)/2][i])%mod;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
